package org.dromara.easyes.common.utils;

import org.dromara.easyes.common.enums.ESIndexSuffixEnum;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * ProductName: easy-es
 * Package: org.dromara.easyes.common.utils
 * Description:
 * @Author: 86631561@163.coom
 * Date: 2023/8/1 10:36
 * UpdateUser: 86631561@163.coom
 * UpdateDate: 2023/8/1 10:36
 * UpdateRemark: The modified content
 * Version: 1.0.0
 * <p>
 * Copyright © 2023 86631561@163.coom Technologies Inc. All Rights Reserved
 **/
public class IndexSuffixUtils {


    public static String getSuffix(ESIndexSuffixEnum esIndexSuffixEnum) {
        if(esIndexSuffixEnum== ESIndexSuffixEnum.BY_MONTH){
            return byMonth();
        }
        else if(esIndexSuffixEnum==ESIndexSuffixEnum.BY_DAY){
            return byDay();
        }
        else if(esIndexSuffixEnum==ESIndexSuffixEnum.ALL){
            return byAll();
        }else if(esIndexSuffixEnum==ESIndexSuffixEnum.BY_YEAR){
            return byYear();
        }
        return "";
    }

    private static String byYear() {
        //根据日期生成index
        String suffix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy"));
        return suffix;
    }

    private static String byMonth() {
        //根据日期生成index
        String suffix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
        return suffix;
    }

    private static String byDay() {
        //根据日期生成index
        String suffix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        return suffix;
    }

    private static String byAll() {
        return "*";
    }
}
